package com.lishu.carsafe.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lishu.carsafe.R;
import com.lishu.carsafe.model.entity.AlarmInfo;

import java.util.List;

/**
 * describe:
 *
 * @author:ZhangWei(张伟) date:2020/6/6
 * time:11:47
 * motto:高山仰止，景行行止，虽不能至，心向往之。
 */
public class MonitorWarnAdapter extends RecyclerView.Adapter<MonitorWarnAdapter.WarnViewHold> {
    private List<AlarmInfo> list;
    private Context context;
    private LayoutInflater inflater;
    public MonitorWarnAdapter(Context context){
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void setList(List<AlarmInfo> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public WarnViewHold onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = inflater.inflate(R.layout.activity_monitor_warn_item,viewGroup,false);
        return new WarnViewHold(view);
    }

    @Override
    public void onBindViewHolder(@NonNull WarnViewHold warnViewHold, int i) {
        warnViewHold.tv_monitor_car.setText(list.get(i).getAlarmContent());
        warnViewHold.tv_monitor_time.setText(list.get(i).getAlarmTime());
        warnViewHold.tv_monitor_car_line.setText(list.get(i).getState()==0?"未处理":"已处理");
    }

    @Override
    public int getItemCount() {
        return list==null?0:list.size();
    }

    public static class WarnViewHold extends RecyclerView.ViewHolder{
        TextView tv_monitor_car;
        TextView tv_monitor_time;
        TextView tv_monitor_car_line;

        public WarnViewHold(@NonNull View itemView) {
            super(itemView);
            tv_monitor_car =itemView.findViewById(R.id.tv_monitor_car);
            tv_monitor_time =itemView.findViewById(R.id.tv_monitor_time);
            tv_monitor_car_line =itemView.findViewById(R.id.tv_monitor_car_line);
        }
    }

}
